﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SWGeneracionE.Libraries
{
    public class ExcelResult : ActionResult
    {
        public string FileName { get; set; }
        public PartialViewResult _result { get; set; }

        public ExcelResult(string filename, PartialViewResult result)
        {
            this.FileName = filename;
            this._result = result;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.Clear();
            context.HttpContext.Response.AppendHeader("content-disposition", "attachment;filename=" + this.FileName);
            context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.HttpContext.Response.ContentType = "application/vnd.ms-excel";
            _result.ExecuteResult(context);
        }
    }
}